#include "OOPObjectTest.h"
#include "TestClass.h"
#include <iostream>

using namespace std;

OOPObjectTest::OOPObjectTest(void)
{
}

OOPObjectTest::~OOPObjectTest(void)
{
}

void OOPObjectTest::test ()
{
	int testPoint = 0;
// 	WaitForSingleObject (hMutex, INFINITE);
// 	cout << "OOPObjectTest start" << endl;
// 	ReleaseMutex (hMutex);
	TestClass1 stackTestClass;
	if (stackTestClass.isOnHeap () == true) {
		WaitForSingleObject (hMutex, INFINITE);
		cerr << __FILE__ << "(" << __LINE__ << ": OOPObject Test Point " << testPoint << " Fail" << endl;
		ReleaseMutex (hMutex);
	}
	++testPoint;

	TestClass1 * singleTestClass = new TestClass1 ();
	if (singleTestClass->isOnHeap () == false) {
		WaitForSingleObject (hMutex, INFINITE);
		cerr << __FILE__ << "(" << __LINE__ << ": OOPObject Test Point " << testPoint << " Fail" << endl;
		ReleaseMutex (hMutex);
	}
	++testPoint;

	int elemNum = 2;
	TestClass1 *multipleTestClass;
	TestClass1::newArray (&multipleTestClass, elemNum);
	for (int i = 0; i < elemNum; ++i) {
		if (multipleTestClass[i].isArrOnHeap () == false) {
			WaitForSingleObject (hMutex, INFINITE);
			cerr << __FILE__ << "(" << __LINE__ << ": OOPObject Test Point " << testPoint << " Fail" << endl;
		}
		++testPoint;
	}

	TestClass2 innerTestClass;
	if (innerTestClass.field.isOnHeap () == true) {
		WaitForSingleObject (hMutex, INFINITE);
		cerr << __FILE__ << "(" << __LINE__ << ": OOPObject Test Point " << testPoint << " Fail" << endl;
		ReleaseMutex (hMutex);
	}
	++testPoint;

// 	delete singleTestClass;
	delete [] multipleTestClass;
// 	WaitForSingleObject (hMutex, INFINITE);
// 	cout << "OOPObjectTest end" << endl;
// 	ReleaseMutex (hMutex);
}